# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

from django.db import models

# Create your models here.


class BaseModel(models.Model):
    creator = models.CharField(max_length=32, verbose_name="创建者")
    updated_by = models.CharField(max_length=32, null=True, blank=True, verbose_name="修改人")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="修改时间")
    is_deleted = models.BooleanField(default=False)

    class Meta:
        abstract = True


class TaskRecord(BaseModel):
    CREATED = "CREATED"
    FAILED = "FAILED"
    RUNNING = "RUNNING"
    SUSPENDED = "SUSPENDED"
    REVOKED = "REVOKED"
    FINISHED = "FINISHED"
    TASK_STATUS = (
        (CREATED, CREATED),
        (FAILED, FAILED),
        (RUNNING, RUNNING),
        (SUSPENDED, SUSPENDED),
        (REVOKED, REVOKED),
        (FINISHED, FINISHED),
    )
    task_name = models.CharField(max_length=32, verbose_name="任务名")
    task_id = models.IntegerField(null=True, verbose_name="任务ID")
    biz_id = models.IntegerField(verbose_name="业务ID")
    tpl_id = models.IntegerField(verbose_name="模板ID")
    status = models.CharField(max_length=10, choices=TASK_STATUS, default=CREATED, verbose_name="任务状态")
    ip = models.GenericIPAddressField(verbose_name="ip", null=True)
    tpl_name = models.CharField(max_length=100, verbose_name="模板名称")
    task_url = models.CharField(max_length=255, null=True, verbose_name="任务链接")

    class Meta:
        db_table = "task_record"
        verbose_name = "任务执行记录"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.task_name